package com.umakr.ax.common.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.google.common.collect.Maps;
import com.umakr.ax.common.model.Code;
import com.umakr.ax.common.mapper.CodeMapper;
import com.umakr.ax.core.base.BaseService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 编码表 服务实现类
 * </p>
 *
 * @author Umakr-Code-Generator
 * @since 2017-12-30
 */
@Service
public class CodeService extends BaseService<CodeMapper, Code>{

    public Object getCodeByTypeName(String typeName) {
        int errorCode = 0 ;
        String msg;
        Map<String,Object> data = Maps.newLinkedHashMap();
        EntityWrapper<Code> codeWrapper = new EntityWrapper<>();
        codeWrapper.eq("code_type_name", typeName);
        Code code = selectOne(codeWrapper);
        if(code == null){
            msg = "当前编码不存在";
        }else {
            data.put("id",code.getId());
            data.put("codeName",code.getCodeName());
            data.put("codeId",code.getCodeId());
            data.put("codeParentId",code.getCodeParentId());
            data.put("codeLevel",code.getCodeLevel());
            data.put("codeTypeName",code.getCodeTypeName());
            data.put("codeValue",code.getCodeValue());
            errorCode = 1 ;
            msg = "获取成功";
        }
        return  resultMap(data,errorCode,msg);
    }
}
